<script setup>
import { ref, computed, onMounted } from 'vue'
import { RouterView, useRoute } from 'vue-router'
import Layout from '@/layout/index.vue'
import { useCssVar } from '@vueuse/core'
import { useThemeStore } from '@/stores'
import zh from 'ant-design-vue/locale/zh_CN'
import dayjs from 'dayjs'
import 'dayjs/locale/zh-cn'
dayjs.locale('zh-cn')

const route = useRoute()
const primaryColor = computed(() => useThemeStore().primaryColor)
const theme = ref({
  token: {
    colorPrimary: primaryColor, // 主色调
    colorSuccess: '#52c41a', // 成功色
    colorWarning: '#faad14', // 警告色
    colorError: '#ff4d4f', // 错误色
  },
  components: {
    button: {
      colorPrimary: 'var(--primary-color)',
    },
  },
})
onMounted(() => {
  useCssVar('--color').value = primaryColor.value
})
</script>

<template>
  <a-style-provider hash-priority="high">
    <a-config-provider :locale="zh" :theme="theme">
      <RouterView v-if="route.name === 'login'" />
      <Layout v-else>
        <RouterView
          v-if="route.meta.keepAlive"
          v-slot="{ Component }"
          :key="'keepalive' + route.fullPath"
        >
          <keep-alive>
            <component :is="Component" />
          </keep-alive>
        </RouterView>
        <RouterView v-else v-slot="{ Component }" :key="'noKeepalive' + route.fullPath">
          <component :is="Component" />
        </RouterView>
      </Layout>
    </a-config-provider>
  </a-style-provider>
</template>

<style scoped>
#nprogress .bar {
  background-color: var(--color) !important;
}
#nprogress .peg {
  box-shadow:
    0 0 10px var(--color),
    0 0 5px var(--color) !important;
}

:deep(.ant-btn) {
  display: flex;
  align-items: center;
  justify-content: center;
}
</style>
